<template>
	<view>
		<u-loading-page
			v-if="!error"
			:loading="true"
			:loading-text="text"
		></u-loading-page>
		<view v-else class="container">
			<u-empty :text="error" icon="/static/empty-permission.png">
				<view class="empty">
					<u-button type="primary" text="退出" @click="onExit"></u-button>
				</view>
			</u-empty>
		</view>
	</view>
</template>

<script>
import { onLaunchCheck, getSystemConfigName } from '@/src/config.js'
export default {
	data() {
		return {
			text: '正在读取用户信息',
			error: '',
		}
	},
	onReady() {
		onLaunchCheck()
			.then(() => {
				this.$store
					.dispatch('getLoginInfo')
					.then(() => {
						this.text = '欢迎使用' + getSystemConfigName()
						// 已登录
						uni.switchTab({
							url: '/pages/dashboard/dashboard',
						})
					})
					.catch(() => {
						this.text = '正在跳转登录界面'
					})
			})
			.catch((error) => {
				this.error = error
			})
	},
	methods: {
		onExit() {
			plus.runtime.quit()
		},
	},
}
</script>

<style lang="scss" scoped>
.container {
	padding: 150px 60px 0;
	@include flex(column);
	align-items: center;
	justify-content: center;
}

.empty {
	margin-top: 30px;
}
</style>
